﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Minestorm.Evolved.Animation
{
    public class EasingManager
    {
        private List<IEasing> _easings = new List<IEasing>();

        public void AddEasing(IEasing easing)
        {
            _easings.Add(easing);
            easing.EasingManager = this;
        }

        public void RemoveEasing(IEasing easing)
        {
            _easings.Remove(easing);
        }

        public void Update(GameTime gameTime)
        {
            for (int i = 0; i < _easings.Count; i++)
            {
                var easing = _easings[i];

                if (easing.State == EasingState.Stopped)
                    continue;

                float elapsed = (float)gameTime.TotalGameTime.TotalMilliseconds - (float)easing.LastRun.TotalMilliseconds;

                if (elapsed >= Easing.Interval)
                    easing.Update(gameTime);
            }
        }
    }
}
